from appium import webdriver
import time
from appium.options.common.base import AppiumOptions
from appium.webdriver.common.appiumby import AppiumBy
def post_to_xiaohongshu(image_dir):
    options = AppiumOptions()
    options.load_capabilities({
        "platformName": "Android",
        "appium:platformVersion": "13",
        "appium:deviceName": "eyc6spinnnmw4h89",
        "appium:appPackage": "com.xingin.xhs",
        "appium:appActivity": "com.xingin.xhs.index.v2.IndexActivityV2",
        "appium:noReset": True,
        "appium:automationName": "UiAutomator2",
        "appium:ensureWebviewsHavePages": True,
        "appium:nativeWebScreenshot": True,
        "appium:newCommandTimeout": 3600,
        "appium:connectHardwareKeyboard": True
    })

    driver = webdriver.Remote("http://localhost:4723/wd/hub", options=options)
    el1 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().text(\"我\")")
    el1.click()
    time.sleep(5)
    el3 = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="1粉丝")
    el3.click()
    time.sleep(5)

    driver.quit()
if __name__ == '__main__':
    post_to_xiaohongshu("../story_images/story_20250306_1")